PTA的Python练习题(十) | 您所在的位置:网站首页 › pta python题库 › PTA的Python练习题(十) |
从 第3章-22 输出大写英文字母 开始 1. a=str(input()) b='' for i in a: if 'A'0: print(b) else: print('Not Found')
2.
3. 判断素数: 思路1):因此判断一个整数m是否是素数,只需把 m 被 2 ~ m-1 之间的每一个整数去除,如果都不能被整除,那么 m 就是一个素数。 思路2):另外判断方法还可以简化。m 不必被 2 ~ m-1 之间的每一个整数去除,只需被 2 ~ 直接求素数没有什么思路,但是我们可以反过来,先求非素数,再减去非素数: a,b=map(int,input().split()) c=0 c2=0 count=0 count2=0 for i in range(a,b+1): for n in range(2,i): if i%n==0: c=c+1 count=count+i break for i in range(a,b+1): count2=count2+i c2=c2+1 print('{} {}'.format(c2-c,count2-count)) |
CopyRight 2018-2019 实验室设备网 版权所有 |